#!/bin/bash
#set -n
#set -x #undo
#echo "# parms=$#" #undo
if [[ (-z "$I") || (-z "${NO_SET+x}") ]] ; then
#set +x #undo
	NO_SET=
	WRITE=
	while (( $# > 0 )) ; do
	case $1 in
	(-n)
		NO_SET=$1
		shift 1
		;;
	(-w)
		WRITE=$1
		shift 1
		;;
	(*)
		echo "Unrecognized option=$1" >&2
		break
		;;
	esac
	done
	function setupddwnenv {
		envname=$1
#set -x
		envvalue="$2"
		eval "export $envname=\"$envvalue\""
		if [[ -n "$WRITE" ]] ; then
			echo "let \$$envname=\"$envvalue\"" >> $sofile
		fi
		eval "export $(echo $envname | tr '[:lower:]' '[:upper:]')=\"$envvalue\""
		if [[ -n "$WRITE" ]] ; then
			echo "let \$$(echo $envname | tr '[:lower:]' '[:upper:]')=\"$envvalue\"" >> $sofile
		fi
	}
#set -x #undo
	if [[ -n "$WRITE" ]] ; then
		export sofile="$I/soenv"
		rm -f $sofile
	fi
#set +x #undo
	setupddwnenv i "$HOME/bin"
fi
